package com.tree.stack;

import org.apache.commons.lang3.StringUtils;

import java.util.Scanner;
import java.util.Stack;

/**
 * package com.tree.stack
 * description:
 *
 * @author tree
 * @date 2019-10-11 11:23
 */
public class StackUtil {
    private static String s = "3,5,4,7,8,2,1";
//    private static String s = "3,5,4";//,7,8,2,1";
//    private static String s = "2,4,1,7";//,7,8,2,1";
    public static Stack<Integer> getStack(boolean init){
        Stack<Integer> stackData = new Stack<Integer>();
        if(init){

            String[] arr = s.split(",");
            for (String s1 : arr) {
                stackData.push(Integer.parseInt(s1));
            }
        }else {
            System.out.println("请输入：");
            Scanner input = new Scanner(System.in);
            String str = input.nextLine();
            while (str != null && !"".equals(str)) {
                stackData.push(Integer.parseInt(str));
                str = input.nextLine();
            }
        }
        return stackData;
    }
}
